package edu.fudan.model;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToOne;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

@Entity
@Table(name = "book_meeting_room")
@Searchable
@XmlRootElement
public class BookMeetingRoom extends BaseObject implements Serializable {
    private static final long serialVersionUID = 3832626162173359411L;

    private Long id;
    private MeetingRoom meetingRoom; 
    private User user;
    private String description;
    private java.util.Date startTime;
    private java.util.Date endTime;
    private Integer version;
    
    public BookMeetingRoom() {
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @SearchableId
    public Long getId() {
        return id;
    }
    
    @OneToOne 
    public MeetingRoom getMeetingRoom() {
        return meetingRoom;
    }

    @OneToOne
    public User getUser() {
        return user;
    }
    
    @Column(length = 50)
    @SearchableProperty
    public String getDescription() {
        return description;
    }
    
    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public java.util.Date getStartTime() {
        return startTime;
    }

    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public java.util.Date getEndTime() {
        return endTime;
    }

    @Version
    public Integer getVersion() {
        return version;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public void setMeetingRoom(MeetingRoom meetingRoom) {
        this.meetingRoom = meetingRoom;
    }
    
    public void setUser(User user) {
        this.user = user;
    }
    
    public void setStartTime(java.util.Date startTime) {
        this.startTime = startTime;
    }

    public void setEndTime(java.util.Date endTime) {
        this.endTime = endTime;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    
    public void setVersion(Integer version) {
        this.version = version;
    }
    
    /**
     * {@inheritDoc}
     */
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof BookMeetingRoom)) {
            return false;
        }

        final BookMeetingRoom bookMeetingRoom = (BookMeetingRoom) o;

        return this.hashCode() == bookMeetingRoom.hashCode();
    }
    
    /**
     * {@inheritDoc}
     */
    public int hashCode() {
        return (id!= null ? id.hashCode() : 0);
    }
    
    /**
     * {@inheritDoc}
     */
    public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
                .append("description", this.description)
                .append("startTime", this.startTime)
                .append("endTime", this.endTime);
        return sb.toString();
    }
}
